#!/usr/bin/python
# -*- coding: utf-8 -*-

import glob, sys, os, re, string
import pepe.p_txt.bigtxt as bt
import pepe.glib as g

import pepe.p_filesystem.basic as pfb

fslist = lambda x, y: pfb.fslist(x, patterns=y, recurse=True, return_folders=False)

o = open('tlh_output.csv', 'wb')
#d = open('tlh_output_DROPPED.csv', 'wb')

#files = fslist(  r"""\\dedus9010\Cyrill_Rawdata\EIFFEL_Rev\2010-09-17\extracted\EMEA_FY99-FY02""" + '\x5C', '*.*')
#files = fslist(  r"""E:\Cyrill_Rawdata\EIFFEL_Rev""" + '\x5C', '*.*')
files = fslist(  r"""\\dedus9010\cyrill_rawdata\EIFFEL_IC\2010-09-09\extracted\active""" + '\x5C', '*.*')

if 1: # listing loop
for f in files:   
	print "Checking for truncation: " + f 
	counter+=1
	for line in bt.lines(f):
		if (re.search('Local C\x0D\x0A', line)):
		# or re.search('\d\.\d{2}( |-).{,}\d(,|\.)(?!\d)', line)):
			truncated.append(f)
			countertrunc+=1
			break
		else: pass

if 1: # validation loop
    for f in files:
        if not f in truncated:
            print "Validating: " + f 
            for line in bt.lines(f):
                if re.match('^ {2}[0-9A-Za-z\-]{10}.{28}[0-9A-Za-z]{2}.{56}[A-Za-z0-9]{4}-[A-Za-z0-9]{2}-[A-Za-z0-9]{4}-[A-Za-z0-9]{2}-[A-Za-z0-9]{2}-[A-Za-z0-9]{2}-[A-Za-z0-9]{2}.{21}\.\d{2}', line):
                    o.write(line)
                else:
                    d.write(line)   

o.close()
#d.close()


